package com.ms.education.cms.controller;

import com.ms.education.R;
import com.ms.education.cms.entity.BannerGroup;
import com.ms.education.cms.entity.vo.BannerGroupVo;
import com.ms.education.cms.service.BannerGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-01-21
 */
@Api(description = "轮播图分组查询")
@RestController
@RequestMapping("/cms/banner-group")
public class BannerGroupController {

    @Autowired
    private BannerGroupService bannerGroupService;


    @ApiOperation("查询轮播分组")
    @PostMapping("getBannerGroup")
    public R getBannerGroup(@RequestBody BannerGroupVo bannerGroupVo) {
        List<BannerGroup> res = bannerGroupService.getBannerGroup(bannerGroupVo);
        return R.ok().data("groups", res);
    }

    @ApiOperation("删除分组")
    @PostMapping("deleteBannerGroupsByIds")
    public R deleteBannerGroupsByIds(@RequestBody Integer[] bannerGroupsIds) {
        bannerGroupService.deleteBannerGroupsByIds(bannerGroupsIds);
        return R.ok();
    }


    @PostMapping("saveOrUpdateGroup")
    public R saveOrUpdateGroup(@RequestBody BannerGroup bannerGroup) {
        bannerGroupService.saveOrUpdate(bannerGroup);
        return R.ok();
    }

    @GetMapping("getGroupById/{id}")
    public R getGroupById(@PathVariable("id") Integer id) {
        BannerGroup group = bannerGroupService.getById(id);
        return R.ok().data("group", group);
    }

    //使分组展示
    @PostMapping("showGroup/{id}")
    public R showGroup(@PathVariable("id") Integer id) {
        bannerGroupService.showGroup(id);
        return R.ok();
    }


}
